package xxy.com.yangproject.ui.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;

import java.util.concurrent.atomic.AtomicInteger;

import xxy.com.yangproject.R;
import xxy.com.yangproject.global.Constant;
import xxy.com.yangproject.global.YangApplication;

public class Mydialog extends Dialog {
    private Context mContext;

    public Mydialog(@NonNull Context context) {
        super(context);
    }

    public Mydialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        mContext = context;
    }

    protected Mydialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_test);
        findViewById(R.id.button_test).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("click");
            }
        });
        findViewById(R.id.button_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        attributes.width = getContext().getResources().getDisplayMetrics().widthPixels / 2;
        attributes.height = getContext().getResources().getDisplayMetrics().widthPixels / 2;
        getWindow().setAttributes(attributes);
    }

    @Override
    protected void onStart() {
        super.onStart();
        int integer = ((YangApplication) mContext.getApplicationContext()).getAtomicInteger().incrementAndGet();
        LogUtils.eTag(Constant.TAG, "AtomicInteger调用incrementAndGet()方法的结果 ： " + integer);

//        if (getWindow() != null) {
//            WindowManager windowManager = getWindow().getWindowManager();
//            final Rect point = new Rect();
//            windowManager.getDefaultDisplay().getRectSize(point);
//            WindowManager.LayoutParams attributes = getWindow().getAttributes();
//            attributes.width = (int)(point.width() * 0.5);
//            attributes.height = (int)(point.height() * 0.3);
//            getWindow().setAttributes(attributes);
//        }

    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }
}
